@extends('app')
@section('content')
<ul class="nav nav-tabs">
    <li><a href="{{ url('/admin/setting/roles')}}">信息列表</a></li>
    <li class="active"><a href="{{ url('/admin/setting/roles/create')}}">信息编辑</a></li>
</ul>
<form id="roleForm" class="" method="post" action="{{ url('/admin/setting/roles')}}">
    <div class="panel panel-info mt20">
        <div class="panel-heading">角色信息</div>
        <div class="panel-body">
            <div class="form-group clearfix">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">所属组别</label>
                <div class="col-sm-9 col-xs-12">
                    <select name="group" class="form-control">
                        @foreach($group as $gp)
                        <option value="{{$gp->id}}" @if(!empty($group_id)&&$group_id == $gp->id) selected @endif>{{$gp->display_name}}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="form-group clearfix">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">角色名称</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="text" class="form-control" name="name" placeholder="昵称" value="@if(!empty($result)){{ $result->name }}@endif">
                </div>
            </div>
            <div class="form-group clearfix">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">中文名称</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="text" class="form-control" name="display_name" placeholder="中文名称" value="@if(!empty($result)){{ $result->display_name }}@endif">
                </div>
            </div>
            <div class="form-group clearfix">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">描述</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="text" class="form-control" name="description" placeholder="描述" value="@if(!empty($result)){{ $result->description }}@endif">
                </div>
            </div>
        </div>
    </div>
    <div class="panel panel-default mt20">
        <div class="panel-body table-responsive">
            <table class="table">
                @foreach($topPerm as $tppm)
                <thead>
                   <tr class="info">
                    <th colspan=5>
                        <label>
                            <input type="checkbox" name="{{$tppm->name}}" value="{{$tppm->id}}"  @if(!empty($perms) &&in_array($tppm->id,$perms)) checked @endif>
                            &nbsp;&nbsp;{{$tppm->display_name}}
                        </label>
                    </th>
                   </tr>   
                </thead>
                <tbody class="{{$tppm->name}}">
                    @foreach($tppm->childrens as $key=>$tpch)
                    @if($key%5 == 0 )<tr>@endif
                        <td>
                            <label>
                               <input type="checkbox" name="{{$tpch->name}}"  value="{{$tpch->id}}" @if(!empty($perms) && in_array($tppm->id,$perms)) checked @endif>
                               &nbsp;&nbsp;{{$tpch->display_name}}
                            </label>
                        </td>
                    @if($key%5 == 0 && $key!=0 && $key!=5 && $key!=10&& $key!=15&& $key!=20&& $key!=25&& $key!=30&& $key!=40 )
                    </tr>
                    @endif
                    @endforeach
                    </tr>
                </tbody>
                @endforeach
            </table>
        </div>
    </div>
    {!! csrf_field() !!}
    <input type="hidden" name="roleid" value="@if(!empty($result)){{ $result->id }}@endif">
    <div class="form-inline">
            <div class="form-group">
              <button type="button" class="btn btn-info" onclick="saveData('/admin/setting/roles','roleForm')">
                    <i class="icon-ok bigger-110"></i>
                    Submit
              </button>  
            </div>
                    
            <div class="form-group col-xs-offset-1">
                <button type="reset" class="btn">
                    <i class="icon-undo bigger-110"></i>
                    Reset
                </button>
            </div>
        </div>
</form>
<script type="text/javascript">
<!--
$('input').iCheck({
	checkboxClass: 'icheckbox_flat-blue',
    radioClass: 'iradio_flat-blue',
    increaseArea: '-10' // optional
});
//处理全选函数
$('input:checkbox').on('ifChecked', function(event){
	$('.'+$(this).attr('name')+' input:checkbox').iCheck('check');
});
$('input:checkbox').on('ifUnchecked', function(event){
	$('.'+$(this).attr('name')+' input:checkbox').iCheck('uncheck');
});

//当已经全选时，默认全选按钮选中
$(function() {
	$('.table>tbody').each(function() {
		var a = true;
		$(this).find('input:checkbox').each(function() {
			if($(this)[0].checked != true) {
				a = false;
				return false;
			}
		});
		if(a) $('input[name='+$(this).attr('class')+']:checkbox')[0].checked = true;
	});
});
$(function(){
	/***图片上传****/
	$("#uploadimg").uploadify({
	    'formData'     : {
	        'fileField':'upfile',
	        '_token':'{{ csrf_token() }}'
	    },
	    "width"           : 120,
	    "height"          : 30,
	    "queueSizeLimit"  :1,
	    "swf"             : "{{ asset('/js/uploadify/uploadify.swf') }}",
	    "fileObjName"     : "upfile",
	    "buttonText"      : "上传图片",
	    "uploader"        : '/admin/upload/logo/{{!empty($result)?$result->id:0}}',
	    'removeTimeout'	  : 1,
	    'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
	    'onUploadSuccess':function(file, data, response){
	    	var data = eval('(' + data + ')');
	        if (data.status == 'success') {

	            var html="<div><img src='"+data.attach+"' /></div>";
	            $('#imgbox').html(html);
	        }else{
	            alert(data.msg);
	            return false;
	        }

	    }

	});
	
});
//-->
</script>
@endsection
